import { post } from '../../utils/fetch'
import * as commonService from '../common'
import { cashFlowMainMsg, cashFlowDetailMsg, cashFlowMainHistogram  } from '../../utils/api'
import * as Libs from '../../utils/Libs'
import * as _ from 'lodash'

export const getMainMsg = async (params) => {
  return post(cashFlowMainMsg(params), {})
}

export const getDetailMsg = async (params) => {
  return post(cashFlowDetailMsg(params), {})
}

export const getMainHistogram = async(params) => {
  return post(cashFlowMainHistogram(params), {})
}

export const buildD = (tit, total, xq) => {
  const _title = { //营业利润title
    name: tit,
    amount: total.sumMoney || 0,
    yoy: (total.onRise || 0) + '%',
    qoq: (total.linkRise || 0) + '%'
  }
  let _content = []
  _.map(xq, (v) => {
    _content.push(geneContent(v))
  })
  return {
    title: _title,
    content: _content
  }
}

const geneContent = (v) => {
  const linked = commonService.getLinked(v.code) || {}
  let params = Object.assign({}, v, linked)
  // const _linked = v.isDetails === 1 ? params : undefined
  const _linked = params
  return {
    name: v.codeName,
    amount: Libs.numberUpperFormat(v.sumMoney || 0),
    linked: _linked,
    yoy: (v.onRise || 0)+ "%",
    qoq: (v.linkRise || 0) + "%",
  }
}


export const buildSummary = (tit, total) => {
  const linked = commonService.getLinked(total.code) || {}
  let params = Object.assign({}, total, linked)
  const _linked = params
  return {
    name: tit,
    linked: _linked,
    amount: Libs.numberUpperFormat(total.sumMoney || 0),
    yoy: (total.onRise || 0) + "%",
    qoq: (total.linkRise || 0) + "%",
  }
}
